package com.hello.system.service.impl;

import java.util.List;
import com.hello.common.core.utils.DateUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hello.system.mapper.RentalMemberInfoMapper;
import com.hello.system.domain.RentalMemberInfo;
import com.hello.system.service.IRentalMemberInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 会员信息Service业务层处理
 * 
 * @author hello
 * @date 2025-07-20
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RentalMemberInfoServiceImpl extends ServiceImpl<RentalMemberInfoMapper, RentalMemberInfo> implements IRentalMemberInfoService 
{
    private final RentalMemberInfoMapper rentalMemberInfoMapper;

    /**
     * 查询会员信息
     * 
     * @param memberId 会员信息主键
     * @return 会员信息
     */
    @Override
    public RentalMemberInfo selectRentalMemberInfoByMemberId(Long memberId)
    {
        return rentalMemberInfoMapper.selectRentalMemberInfoByMemberId(memberId);
    }

    /**
     * 根据用户ID查询会员信息
     * 
     * @param userId 用户ID
     * @return 会员信息
     */
    @Override
    public RentalMemberInfo selectRentalMemberInfoByUserId(Long userId)
    {
        RentalMemberInfo query = new RentalMemberInfo();
        query.setUserId(userId);
        List<RentalMemberInfo> list = rentalMemberInfoMapper.selectRentalMemberInfoList(query);
        return list.isEmpty() ? null : list.get(0);
    }

    /**
     * 查询会员信息列表
     * 
     * @param rentalMemberInfo 会员信息
     * @return 会员信息
     */
    @Override
    public List<RentalMemberInfo> selectRentalMemberInfoList(RentalMemberInfo rentalMemberInfo)
    {
        return rentalMemberInfoMapper.selectRentalMemberInfoList(rentalMemberInfo);
    }

    /**
     * 新增会员信息
     * 
     * @param rentalMemberInfo 会员信息
     * @return 结果
     */
    @Override
    public int insertRentalMemberInfo(RentalMemberInfo rentalMemberInfo)
    {
        rentalMemberInfo.setCreatedTime(DateUtils.getNowDate());
        rentalMemberInfo.setUpdatedTime(DateUtils.getNowDate());
        return rentalMemberInfoMapper.insertRentalMemberInfo(rentalMemberInfo);
    }

    /**
     * 修改会员信息
     * 
     * @param rentalMemberInfo 会员信息
     * @return 结果
     */
    @Override
    public int updateRentalMemberInfo(RentalMemberInfo rentalMemberInfo)
    {
        rentalMemberInfo.setUpdatedTime(DateUtils.getNowDate());
        log.info("正在更新会员信息 - ID: {}, 钱包余额: {}", 
                rentalMemberInfo.getMemberId(), rentalMemberInfo.getWalletBalance());
        int result = rentalMemberInfoMapper.updateRentalMemberInfo(rentalMemberInfo);
        log.info("会员信息更新结果: {}, 影响行数: {}", result > 0 ? "成功" : "失败", result);
        return result;
    }


    /**
     * 批量删除会员信息
     * 
     * @param memberIds 需要删除的会员信息主键
     * @return 结果
     */
    @Override
    public int deleteRentalMemberInfoByMemberIds(Long[] memberIds)
    {
        return rentalMemberInfoMapper.deleteRentalMemberInfoByMemberIds(memberIds);
    }

    /**
     * 删除会员信息信息
     * 
     * @param memberId 会员信息主键
     * @return 结果
     */
    @Override
    public int deleteRentalMemberInfoByMemberId(Long memberId)
    {
        return rentalMemberInfoMapper.deleteRentalMemberInfoByMemberId(memberId);
    }
}
